package com.qf.util;

import java.io.IOException;
import java.io.InputStream;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.Properties;

import com.alibaba.druid.pool.DruidDataSource;
import com.alibaba.druid.pool.DruidDataSourceFactory;

/**
* @author 作者：Eric E-mail:15665627080@163.com
* @version 创建时间：2020年7月10日 下午7:05:19
* 类说明
*/
public class JDBCUtil {
	static Properties p=new Properties();
	
	static DruidDataSource ds;
	static{
		InputStream in = JDBCUtil.class.getClassLoader().getResourceAsStream("jdbc.properties");
		try {
			p.load(in);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		try {
			ds=(DruidDataSource) DruidDataSourceFactory.createDataSource(p);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		
	
	
	}
	
	
	public static Connection getCon(){
		Connection con=null;
		try {
			con = ds.getConnection();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return con;
	}
	
	
	public static void colseCon(Connection con){
		if(con!=null){
			try {
				con.close();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}

}
